Repository navigation
IDBDatabase: make the upgrade example work for existing databases - #45955
Open
AsifMahsud wants to merge 2 commits into
Open
AsifMahsud wants to merge 2 commits into
AsifMahsud wants to merge 2 commits into
Conversation
Member
|
Holding this until mdn/dom-examples#404 gets merged. And then we'll update all the other pages too. |
Contributor
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Reworks the
onupgradeneededhandler in theIDBDatabaseexample so it handles upgrades from an older version, not just first-time creation:event.oldVersionand applies each upgrade step the user hasn't had yet. Version 1 creates thetoDoListstore and its date/time indexes; version 2 adds thenotifiedindex to the existing store, which it gets from the upgrade transaction (DBOpenRequest.transaction.objectStore()) instead of callingcreateObjectStore()again.open()call asks for version 2 to match.node.appendChildtypo (the variable isnote), plus a missing full stop in a comment.Motivation
As the issue says, the old handler always called
createObjectStore("toDoList"), so it only worked when the database didn't exist yet. Bumping the version for anyone with an existing database threw aConstraintErrorand aborted the upgrade. I checked this withfake-indexeddb: after creating the database at version 1, the old handler fails on the upgrade to version 2 withConstraintError, while the new handler produces the same six indexes both for a fresh install at version 2 and for an upgrade from version 1.Additional details
IndexedDB spec,
IDBVersionChangeEvent.oldVersion(0 for a new database) andIDBOpenDBRequest.transactionduring an upgrade.Related issues and pull requests
Fixes #26638